{include file="admin/common/header" /}
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">

            <div class="layui-form-item">
                <label class="layui-form-label">节点类型</label>
                <div class="layui-input-block">
                    <input type="radio" lay-filter="type_mode" name="type" value="1" title="新建文档" checked>
                    <input type="radio" lay-filter="type_mode" name="type" value="2" title="新建分组">
                    <input type="radio" lay-filter="type_mode" name="type" value="3" title="新建链接">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">标题</label>
                <div class="layui-input-block ">
                    <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item type_mode type_3" style="display: none">
                <label class="layui-form-label required">链接地址</label>
                <div class="layui-input-block ">
                    <input type="text" name="link" lay-verify="url" autocomplete="off" placeholder="请输入链接地址"
                           class="layui-input">
                </div>
            </div>


        </div>
    </div>
    <div class="bottom">
        <input type="hidden" id="book_id" name="book_id" value="{$book_id}">
        <input type="hidden" id="pid" name="pid" value="{$pid}">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file="admin/common/footer" /}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;

    form.on('radio(type_mode)', function (data) {
      $('.type_mode').hide();
      if (data.value == 3) {
        $('.type_' + data.value).show();
      }
    })
    form.render();

    form.on('submit(admin-save)', function (data) {
      $.ajax({
        url: "/app/book/admin/doc/add",
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (res) {
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              window.location.reload();
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    });
  })
</script>
<script>
</script>
</body>
</html>
